﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RAP.Framework.Libary.Utils
{
    /// <summary>
    /// 异常对象扩展
    /// </summary>
    public static partial class Extensions
    {
        /// <summary>
        /// 将异常对象转换成JSON格式的字符串
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        public static string ToMessage( this Exception e )
        {
            return $"error:{e.Message}\r\nstackTrace:{e.StackTrace}";
        }

        /// <summary>
        /// 将Exception对象转换成标准的键值对象
        /// </summary>
        /// <param name="exc"></param>
        /// <returns></returns>
        public static IDictionary ToDictionary( this Exception exc )
        {
            return new Hashtable
            {
                {
                    "errorCode", -9999
                },
                {
                    "errorMessage", exc.ToMessage ( )
                }
            };
        }
    }
}
